$(function () {
	//延迟加载等待html渲染完成
	setTimeout(function () {
		document.getElementById("position").scrollIntoView();
	}, 10);
});
if (proBaseInfo != undefined && proBaseInfo != null && proBaseInfo != "") {
	if (proBaseInfo.proType == "XS") {
		$("#bttitle").html("收支情况");
	}
}

function jump(flag, e) {
	$($(e).parent().parent().find("li")).each(function () {
		$(this).prop("class", "");
	});
	$(e).parent().prop("class", "active");
	for (var i = 1; i <= 8; i++) {
		if (i == flag) {
			$("#tab" + i).show();
		} else {
			$("#tab" + i).hide();
		}
	}
	if (flag == 5) {
		change();
	}
	if (flag==4){
        findOkrFp($CertusJsonAjax);
	}
}
change();
function toReturnJump(flag) {
    $("#jp"+flag).prop("class", "active");
	$("#yb4").prop("class", "active");
    $("#yb2").prop("class","");
	for (var i = 1; i <= 8; i++) {
		if (i == flag) {
			$("#tab" + i).show();
		} else {
			$("#tab" + i).hide();
		}
	}
}


// 成员操作权限全选效果
$('.line-check').change(function () {
	var status = $(this).prop("checked");
	if (status) {
		$(this).parent().parent().find(':checkbox').attr("checked", true)
	} else {
		$(this).parent().parent().find(':checkbox').attr("checked", false)
	}
});
$(".isshow").hide();
// 项目整体进展列表
var prgColumns = [{
	id: 'begin_time',
	title: '开始日期',
	type: 'date',
	format: 'yyyy-MM-dd',
	otype: 'time_stamp_ms',
	width: 100,
	columnClass: 'text-center',
}, {
	id: 'end_time',
	title: '结束日期',
	type: 'date',
	format: 'yyyy-MM-dd',
	otype: 'time_stamp_ms',
	width: 100,
	columnClass: 'text-center',
}, {
	id: 'content',
	title: '项目整体进展',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'next_step',
	title: '下一步计划',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'operation',
	title: '操作',
	width: 130,
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		var content = "";
		//计算相差多少天
		var d = new Date();
		start = record.createTime.replace(/-/g, "/");
		var startdate = new Date(start);
		var time = d.getTime() - startdate.getTime();
		var days = parseInt(time / (1000 * 60 * 60 * 24));
		//大于三天则不能修改和删除
		if (days <= 3) {
			content += '<button class="btn btn-xs btn-info" onclick="editReport(' + record.id + ');"><i class="fa fa-edit"></i>  编辑</button>';
			content += '  ';
			content += '<button class="btn btn-xs btn-danger" onclick="delReport(' + record.id + ');"><i class="fa fa-trash-o"></i>  删除</button>';
		}
		return content;
	}
}];
$certusUtils.ajax("findReportlists", {
	"proId": proId
}, function (response) {
	var prgOption = {
		lang: 'zh-cn',
		ajaxLoad: false,
		extraWidth: 20,
		// loadURL:'url',
		exportFileName: '项目整体进展',
		datas: response.data,
		columns: prgColumns,
		gridContainer: 'prgContainer',
		toolbarContainer: 'prgToolBarContainer',
		tools: '',
		pageSize: 10,
		pageSizeLimit: [10, 15, 20]
	};
	var prgGrid = $.fn.dlshouwen.grid.init(prgOption);
	prgGrid.load();
});

var ztjzColumns = [{
	id: 'pro_target',
	title: '项目目标',
	type: 'string',
	width: 100,
	columnClass: 'text-center',
}, {
	id: 'krs_desc',
	title: '关键成果',
	type: 'string',
	// width: 230,
	columnClass: 'text-left',
}, {
	id: 'task_fzuser',
	title: '负责人',
	type: 'string',
	hideType: 'lg|md|sm|xs',
	columnClass: 'text-center',
}, {
	id: 'finshtime',
	title: '计划完成时间',
	type: 'string',
	width: 110,
	columnClass: 'text-center',
}, {
	id: 'krwcl',
	title: '完成率',
	type: 'string',
	width: 60,
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		console.log(value);
		var content = value + '%';
		return content;
}
}, {
	id: 'in_percent',
	title: '实际投入率',
	type: 'string',
	width: 100,
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		var content = value + '%';
		return content;
}
}, {
	id: 'finish_cycle',
	title: '进展周期',
	type: 'string',
	width: 140,
	columnClass: 'text-center',
}, {
	id: 'updateTime',
	title: '更新时间',
	type: 'string',
	width: 110,
	columnClass: 'text-center',
}, {
	id: 'rw_desc',
	title: '子任务进展',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'next_plan',
	title: '下一步计划',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'operation',
	title: '操作',
	width: 80,
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record) {
		var content = '';
		if (record.krwcl < 100) {
			if (userId == record.task_fzuser_id) {
				content += '<button class="btn btn-xs btn-info" onclick="rechildren(\'' + record.krs_id + '\');"><i class="icon-refresh"></i>  更新</button>';
			}
		}
		return content;
	}
}];

$certusUtils.ajax("findProZdgzList", {
	"proId": proId
}, function (response) {
	var prgOption = {
		lang: 'zh-cn',
		ajaxLoad: false,
		extraWidth: 20,
		// loadURL:'url',
		exportFileName: '重点工作',
		datas: response.data,
		columns: ztjzColumns,
		gridContainer: 'zdgzContainer',
		toolbarContainer: 'zdgzToolBarContainer',
		tools: '',
		pageSize: 10,
		pageSizeLimit: [10, 15, 20]
	};
	var prgGrid = $.fn.dlshouwen.grid.init(prgOption);
	prgGrid.load();
});

// 客户拜访记录管理数据
var ctlogColumns = [{
	id: 'visit_time',
	title: '拜访日期',
	width: 100,
	type: 'date',
	format: 'yyyy-MM-dd',
	otype: 'time_stamp_ms',
	columnClass: 'text-center'
}, {
	id: 'com_name',
	title: '客户公司',
	width: 100,
	type: 'string',
	columnClass: 'text-center'
},
{
	id: 'customer_name',
	title: '客户名称',
	width: 100,
	type: 'string',
	columnClass: 'text-center'
},
{
	id: 'user_name',
	title: '拜访人',
	width: 75,
	type: 'string',
	columnClass: 'text-center'
},
{
	id: 'content',
	title: '具体内容',
	type: 'string',
	columnClass: 'text-left'
},
{
	id: 'operation',
	title: '操作',
	type: 'string',
	width: 130,
	columnClass: 'text-center',
	resolution: function (value, record) {
		var content = "";
		//计算相差多少天
		var fordate = new Date(record.create_time);
		var nfordate = $.fn.dlshouwen.grid.tools.dateFormat(fordate, "yyyy-MM-dd");

		var d = new Date();
		var start = nfordate.replace(/-/g, "/");
		var startdate = new Date(start);
		var time = d.getTime() - startdate.getTime();
		var days = parseInt(time / (1000 * 60 * 60 * 24));
		//大于三天则不能修改和删除
		if (days <= 3) {
			content += '<button class="btn btn-xs btn-info" onclick="editCtlog(' + record.id + ');"><i class="fa fa-edit"></i>  编辑</button>';
			content += '  ';
			content += '<button class="btn btn-xs btn-danger" onclick="delCtlog(' + record.id + ');"><i class="fa fa-trash-o"></i>  删除</button>';
		}
		return content;
	}
}
];
$certusUtils.ajax("findProVisitList", {
	"projId": proId
}, function (res) {
	var ctlogOption = {
		lang: 'zh-cn',
		ajaxLoad: false,
		extraWidth: 20,
		// loadURL:'url',
		exportFileName: '客户拜访记录',
		datas: res.data,
		columns: ctlogColumns,
		gridContainer: 'ctlogContainer',
		toolbarContainer: 'ctlogToolBarContainer',
		tools: '',
		pageSize: 10,
		pageSizeLimit: [10, 15, 20]
	};
	var ctlogGrid = $.fn.dlshouwen.grid.init(ctlogOption);
	ctlogGrid.load();
});
//删除客户拜访记录
function delCtlog(id) {
	layer.confirm('确认删除此数据？', {
		btn: ['确认', '取消'] //按钮
	}, function () {
		$certusUtils.ajax("delVisit", {
			"id": id
		}, function () {
			toLoadHtml(4, 2);
		})
		layer.msg("删除成功");
	})
}
//编辑客户拜访记录
function editCtlog(id) {
	toLoadHtml(109, id);
}

//投标及收入情况
var bidColumns = [{
	id: 'nowBiddingTime',
	title: '投标金额',
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
    var content = '￥' + value + '元';
    return content;
  }
}, {
	id: 'nowGetTime',
	title: '中标金额',
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
    var content = '￥' + value + '元';
    return content;
  }
}, {
	id: 'nowLoseTime',
	title: '流标金额',
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
    var content = '￥' + value + '元';
    return content;
  }
}, {
	id: 'createTime',
	title: '创建时间',
	type: 'date',
	format: 'yyyy-MM-dd',
	otype: 'time_stamp_ms',
	width: 100,
	columnClass: 'text-center'
}, {
	id: 'userName',
	title: '创建人',
	type: 'string',
	columnClass: 'text-center'
}, {
	id: 'operation',
	title: '操作',
	width: 130,
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record) {
		var content = "";
		//计算相差多少天
		var fordate = new Date(record.createTime);
		var nfordate = $.fn.dlshouwen.grid.tools.dateFormat(fordate, "yyyy-MM-dd");

		var d = new Date();
		var start = nfordate.replace(/-/g, "/");
		var startdate = new Date(start);
		var time = d.getTime() - startdate.getTime();
		var days = parseInt(time / (1000 * 60 * 60 * 24));
		//大于三天则不能修改和删除
		if (days <= 3) {
			content += '<button class="btn btn-xs btn-info" onclick="editbid(\'' + record.id + '\');"><i class="fa fa-edit"></i>  编辑</button>';
			content += '  ';
			content += '<button class="btn btn-xs btn-danger" onclick="delbid(\'' + record.id + '\');"><i class="fa fa-trash-o"></i>  删除</button>';
		}
		return content;
	}
}];
$certusUtils.ajax("findRpbids", {
	"proId": proId
}, function (response) {
	var prgOption = {
		lang: 'zh-cn',
		ajaxLoad: false,
		extraWidth: 20,
		// loadURL:'url',
		exportFileName: '投标和收入情况',
		datas: response.data,
		columns: bidColumns,
		gridContainer: 'bidContainer',
		toolbarContainer: 'bidToolBarContainer',
		tools: '',
		pageSize: 10,
		pageSizeLimit: [10, 15, 20]
	};
	var prgGrid = $.fn.dlshouwen.grid.init(prgOption);
	prgGrid.load();
});

function editReport(id) {
	toLoadHtml(37, id);
}

function editbid(id) {
	toLoadHtml(107, id);
}

function delbid(id) {
	layer.confirm('是否确认删除？', {
		btn: ['确定', '取消'] //按钮
	}, function () {
		$certusUtils.ajax('delBid', {
			"id": id
		}, function () {
			layer.msg("删除成功");
			toLoadHtml(4, 2);
		});
	});
}

function delReport(id) {
	layer.confirm('是否确认删除？', {
		btn: ['确定', '取消'] //按钮
	}, function () {
		$certusUtils.ajax("findDpCount", { "id": id }, function (response) {
			if (response.data > 0) {
				layer.msg("当前进展存在点评数据不能删除");
				return;
			} else {
				$certusUtils.ajax("delReport", {
					"id": id,
					"projId": proId
				}, function () {
					layer.msg("删除成功");
					toLoadHtml(4, 2);
				})
			}
		});

	});
}
// 项目风险列表
var riskColumns = [{
	id: 'createTime',
	title: '日期',
	width: 100,
	type: 'string',
	columnClass: 'text-center',
}, {
	id: 'riskLv',
	title: '级别',
	type: 'string',
	width: 50,
	columnClass: 'text-center',
}, {
	id: 'type',
	title: '风险状态',
	type: 'string',
	codeTable: status,
	width: 80,
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		var content = '';
		if (value == "1") {
			content += '<span style="background:#d9534f;padding:2px 10px;color:white;">开启中</span>';
		}
		if (value == "0") {
			content += '<span style="background:#5cb85c;padding:2px 10px;color:white;">已关闭</span>';
		}
		return content;
	}
}, {
	id: 'riskContent',
	title: '风险和问题',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'riskManage',
	title: '预规避和处理措施',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'operation',
	title: '操作',
	width: 130,
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		var content = "";
		//计算相差多少天
		var d = new Date();
		start = record.createTime.replace(/-/g, "/");
		var startdate = new Date(start);
		var time = d.getTime() - startdate.getTime();
		var days = parseInt(time / (1000 * 60 * 60 * 24));
		//大于三天则不能修改和删除
		if (days <= 3) {
			var editRisk = "editRisk('" + record.id + "');"
			var delRisk = "delRisk('" + record.id + "');";
			var met = {
				'OKR-JCSBU': editRisk,
				'OKR-JCSBD': delRisk
			};
			content = $certusUtils.initOperateAutho($$scope.leftMenu, ['OKR-JCSBU%edit', 'OKR-JCSBD%delete'], met, riskColumns);
		}
		return content;
	}
}];
$certusUtils.ajax("findRiskList", {
	"proId": proId
}, function (response) {
	var riskOption = {
		lang: 'zh-cn',
		ajaxLoad: false,
		extraWidth: 20,
		// loadURL:'url',
		exportFileName: '项目风险',
		datas: response.data,
		columns: riskColumns,
		gridContainer: 'riskContainer',
		toolbarContainer: 'riskToolBarContainer',
		tools: '',
		pageSize: 10,
		pageSizeLimit: [10, 15, 20]
	};
	var riskGrid = $.fn.dlshouwen.grid.init(riskOption);
	riskGrid.load();
});

function editRisk(id) {
	toLoadHtml(39, id);
}

function delRisk(id) {
	layer.confirm('是否确认删除？', {
		btn: ['确定', '取消'] //按钮
	}, function (index) {
		$certusUtils.ajax("delRisk", {
			"id": id,
			"projId": proId
		}, function (response) {
			layer.msg("删除成功");
			toLoadHtml(4, 2);
		})
	});
}

// 决策上报
var makingColumns = [{
	id: 'create_time',
	title: '日期',
	width: 100,
	type: 'date',
	format: 'yyyy-MM-dd',
	otype: 'time_stamp_ms',
	columnClass: 'text-center',
}, {
	id: 'user_name',
	title: '录入人',
	type: 'string',
	width: 75,
	columnClass: 'text-center',
}, {
	id: 'decision_content',
	title: '内容',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'decision_manage',
	title: '结论',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'operation',
	title: '操作',
	width: 130,
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record) {
		var content = "";
		//计算相差多少天
		var d = new Date();
		start = record.createTime.replace(/-/g, "/");
		var startdate = new Date(start);
		var time = d.getTime() - startdate.getTime();
		var days = parseInt(time / (1000 * 60 * 60 * 24));
		//大于三天则不能修改和删除
		if (days <= 3) {
			var editDecision = "editDecision('" + record.id + "');";
			var delDecision = "delDecision('" + record.id + "');";
			var met = {
				'OKR-JCSBU': editDecision,
				'OKR-JCSBD': delDecision
			};
			content = $certusUtils.initOperateAutho($$scope.leftMenu, ['OKR-JCSBU%edit', 'OKR-JCSBD%delete'], met, makingColumns);
		}
		return content;
	}
}];
$certusUtils.ajax("findDecisionList", {
	"proId": proId
}, function (response) {
	var makingOption = {
		lang: 'zh-cn',
		ajaxLoad: false,
		extraWidth: 20,
		// loadURL:'url',
		exportFileName: '决策上报',
		datas: response.data,
		columns: makingColumns,
		gridContainer: 'makingContainer',
		toolbarContainer: 'makingToolBarContainer',
		tools: '',
		pageSize: 10,
		pageSizeLimit: [10, 15, 20]
	};
	var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
	makingGrid.load();
});

function editDecision(id) {
	toLoadHtml(35, id);
}

function delDecision(id) {
	layer.confirm('是否确认删除？', {
		btn: ['确定', '取消'] //按钮
	}, function (index) {
		$certusUtils.ajax("delDecision", {
			"id": id,
			"projId": proId
		}, function () {
			layer.msg("删除成功");
			toLoadHtml(4, 2);
		});
	});
}

function findOkrFp() {
	$certusUtils.ajax("findTargets", {
		"proId": proId
	}, function (result) {
		var data = result.data;
		for (var i = 0; i < data.length; i++) {
			$("#proTarget").append("<option value='" + data[i].id + "'>" + data[i].proTarget + "</option>");
		}
	});
	$certusUtils.ajax("findMemberList", {
		"proId": proId
	}, function (response) {
		var data = response.data;
		for (var i = 0; i < data.length; i++) {
			$("#userId").append("<option value='" + data[i].userId + "'>" + data[i].userName + "</option>");
			$("#userId2").append("<option value='" + data[i].userId + "'>" + data[i].userName + "</option>");
		}
	});
	getList(0);
	//查询本项目成员在别的项目中的任务
	var okrtlistColumns = [{
		id: 'exe_cys',
		title: '季度',
		type: 'string',
		width: 50,
		columnClass: 'text-center',
	}, {
		id: 'pro_name',
		title: '项目名称',
		type: 'string',
		width: 150,
		columnClass: 'text-center',
	}, {
		id: 'pro_target',
		title: '项目目标',
		type: 'string',
		width: 150,
		columnClass: 'text-center',
	}, {
		id: 'krs_desc',
		title: '子任务',
		type: 'string',
		columnClass: 'text-left',
	}, {
		id: 'input_weight',
		title: '投入占比',
		type: 'string',
		width: 75,
		columnClass: 'text-center',
		resolution: function (value, record, column, grid, dataNo, columnNo) {
			if (value==""){
				value=0;
			}
			var content = value + '%';
			return content;
	}
	}, {
		id: 'time',
		title: '完成时间',
		type: 'string',
		width: 100,
		columnClass: 'text-center',
	}, {
		id: 'kr_weight',
		title: 'KR权重',
		type: 'string',
		width: 90,
		columnClass: 'text-center',
		resolution: function (value, record, column, grid, dataNo, columnNo) {
			var content = value + '%';
			return content;
	}
	}, {
		id: 'user_name',
		title: '成果负责人',
		type: 'string',
		width: 100,
		columnClass: 'text-center',
	}];
	$("#okrContainer1").empty();
    $("#okrToolBarContainer1").empty();
    $CertusJsonAjax.dataInit("findOtherWorks", {
		"proId": proId
	}, okrtlistColumns, 'okrContainer1', 'okrToolBarContainer1', 20, [20, 30, 40]);
// }, function (response) {
//     var okrtlistOption = {
//         lang: 'zh-cn',
//         ajaxLoad: false,
//         extraWidth: 20,
//         // loadURL:'url',
//         exportFileName: 'OKR子任务',
//         datas: response.data,
//         columns: okrtlistColumns,
//         gridContainer: 'okrContainer1',
//         toolbarContainer: 'okrToolBarContainer1',
//         tools: '',
//         pageSize: 20,
//         pageSizeLimit: [20, 30, 40]
//     };
//     var okrtlistGrid = $.fn.dlshouwen.grid.init(okrtlistOption);
//     okrtlistGrid.load();
// });


	//初始化右边tree数据
	var setting = {
		view: {
			showIcon: false
		},
		edit: {
			drag: {
				autoExpandTrigger: true,
				prev: dropPrev,
				inner: dropInner,
				next: dropNext
			},
			enable: true,
			showRemoveBtn: false,
			showRenameBtn: false
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			beforeDrag: beforeDrag,
			beforeDrop: beforeDrop,
			beforeDragOpen: beforeDragOpen,
			onDrag: onDrag,
			onDrop: onDrop,
			onExpand: onExpand,
			beforeClick: beforeClick,
			onClick: onClick
		}
	};


	// 标准节点数据
	var zNodes = [{
		id: 1,
		pId: 0,
		name: "战略类项目标准动作",
		open: true,
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 11,
		pId: 1,
		name: "OKR推行",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	},
	{
		id: 111,
		pId: 11,
		name: "每个季度OKR辅导",
		drag: false,
		dropInner: false,
		nocheck: true
	},

	{
		id: 2,
		pId: 0,
		name: "销售类项目标准动作",
		open: true,
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 12,
		pId: 2,
		name: "明确线索信息",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	},
	{
		id: 121,
		pId: 12,
		name: "获取线索信息和客户诉求",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 122,
		pId: 12,
		name: "获取客户计划和预算",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 123,
		pId: 12,
		name: "获取竞争信息",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 124,
		pId: 12,
		name: "获取项目关键决策链和关键人员",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 22,
		pId: 2,
		name: "解决方案确定",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	},
	{
		id: 221,
		pId: 22,
		name: "获取客户需求",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 222,
		pId: 22,
		name: "完成解决方案设计和沟通",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 223,
		pId: 22,
		name: "更新客户计划和预算以及竞争信息",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 32,
		pId: 2,
		name: "商务和合同落地",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	},
	{
		id: 321,
		pId: 32,
		name: "商务设计和报价（含法务）",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 322,
		pId: 32,
		name: "确定交付范围和时间计划",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 323,
		pId: 32,
		name: "确定版本交付功能",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 324,
		pId: 32,
		name: "更新客户计划和预算以及竞争信息",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 325,
		pId: 32,
		name: "合同签订",
		drag: false,
		dropInner: false,
		nocheck: true
	},

	{
		id: 42,
		pId: 2,
		name: "交付",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	},
	{
		id: 421,
		pId: 42,
		name: "设备到货和安装",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 422,
		pId: 42,
		name: "上电自测和问题解决",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 423,
		pId: 42,
		name: "初验和问题解决",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 424,
		pId: 42,
		name: "终验和问题解决",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 425,
		pId: 42,
		name: "问题和需求处理",
		drag: false,
		dropInner: false,
		nocheck: true
	},

	{
		id: 52,
		pId: 2,
		name: "回款",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	},
	{
		id: 521,
		pId: 52,
		name: "维保",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 522,
		pId: 52,
		name: "到货款",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 523,
		pId: 52,
		name: "初验款",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 524,
		pId: 52,
		name: "终验款",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 525,
		pId: 52,
		name: "尾款",
		drag: false,
		dropInner: false,
		nocheck: true
	},

	{
		id: 3,
		pId: 0,
		name: "事务类项目标准动作",
		open: true,
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 13,
		pId: 3,
		name: "降成本、规范运作、提升效率",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	},
	{
		id: 131,
		pId: 13,
		name: "费用降低",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 132,
		pId: 13,
		name: "效率提升改进",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 133,
		pId: 13,
		name: "内部流程和配合改进",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 134,
		pId: 13,
		name: "例会和周报运作规范性",
		drag: false,
		dropInner: false,
		nocheck: true
	},

	{
		id: 4,
		pId: 0,
		name: "部门类项目标准动作",
		open: true,
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 14,
		pId: 4,
		name: "降成本、提升效率",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	},
	{
		id: 141,
		pId: 14,
		name: "费用降低",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 142,
		pId: 14,
		name: "合理化建议贡献",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 143,
		pId: 14,
		name: "效率提升改进",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 144,
		pId: 14,
		name: "内部流程和配合改进",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 145,
		pId: 14,
		name: "新系统使用",
		drag: false,
		dropInner: false,
		nocheck: true
	},

	{
		id: 24,
		pId: 4,
		name: "团队建设和人员管理",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	},
	{
		id: 241,
		pId: 24,
		name: "例会和周报运作规范性",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 242,
		pId: 24,
		name: "完成公司摊派指标任务",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 243,
		pId: 24,
		name: "规章制度规范遵循",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 244,
		pId: 24,
		name: "内部交流和学习",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 245,
		pId: 24,
		name: "人员培养",
		drag: false,
		dropInner: false,
		nocheck: true
	},

	{
		id: 5,
		pId: 0,
		name: "测试类项目标准动作",
		open: true,
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 15,
		pId: 5,
		name: "方案确定和准备",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	},
	{
		id: 151,
		pId: 15,
		name: "费用降低",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 152,
		pId: 15,
		name: "合理化建议贡献",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 153,
		pId: 15,
		name: "效率提升改进",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 154,
		pId: 15,
		name: "内部流程和配合改进",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 155,
		pId: 15,
		name: "新系统使用",
		drag: false,
		dropInner: false,
		nocheck: true
	},

	{
		id: 25,
		pId: 5,
		name: "研发准备",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	},
	{
		id: 251,
		pId: 25,
		name: "测试用例准备",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 252,
		pId: 25,
		name: "测试用例确认和获取",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 253,
		pId: 25,
		name: "研发内部开发",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 254,
		pId: 25,
		name: "公司内完成实验室测试",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 255,
		pId: 25,
		name: "硬件和相关资源准备",
		drag: false,
		dropInner: false,
		nocheck: true
	},

	{
		id: 35,
		pId: 5,
		name: "安装和对接",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	},
	{
		id: 351,
		pId: 35,
		name: "到货",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 352,
		pId: 35,
		name: "软硬件安装",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 353,
		pId: 35,
		name: "上电自测和现网系统对接",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 354,
		pId: 35,
		name: "验证和问题解决",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 355,
		pId: 35,
		name: "现网割接",
		drag: false,
		dropInner: false,
		nocheck: true
	},

	{
		id: 45,
		pId: 5,
		name: "交付",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	},
	{
		id: 451,
		pId: 45,
		name: "设备到货和安装",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 452,
		pId: 45,
		name: "上电自测和问题解决",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 453,
		pId: 45,
		name: "初验和问题解决",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 454,
		pId: 45,
		name: "终验和问题解决",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 455,
		pId: 45,
		name: "问题和需求处理",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 7,
		pId: 0,
		name: "部门重点工作",
		open: true,
		drag: false,
		dropInner: false,
		nocheck: true
	}, {
		id: 70,
		pId: 7,
		name: "年度重点工作",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	}, {
		id: 700,
		pId: 70,
		name: "重点工作跟踪",
		drag: false,
		dropInner: false,
		nocheck: true
	},
	{
		id: 6,
		pId: 0,
		name: "其他",
		open: true,
		drag: false,
		dropInner: false,
		nocheck: true
	}, {
		id: 60,
		pId: 6,
		name: "其他",
		open: false,
		childOuter: false,
		drag: false,
		dropInner: false
	}, {
		id: 600,
		pId: 60,
		name: "其他",
		drag: false,
		dropInner: false,
		nocheck: true
	}
	];
	$.fn.zTree.init($("#treeDemo"), setting, zNodes);
}

function searchByTarget() {
	var proTarget = $("#proTarget").val();
	if (proTarget == "0") {
		$("#krqz").attr("placeholder", "");
		return;
	}
	$certusUtils.ajax("findTotalWeight", {
		"targetId": $("#proTarget").val(),
		"exeCys": $("#exeCys").val()
	}, function (result) {
		var data = result.data;
		if (data > 100) {
			$("#krqz").attr("placeholder", "剩余权重0%");
		} else {
			var sy = 100 - data;
			$("#krqz").attr("placeholder", "剩余权重" + sy + "%");
		}
	});
	getList(proTarget);
}
// OKR计划和分配列表
function getList(targetId) {
	var okrColumns = [{
		id: 'exe_cys',
		title: '季度',
		type: 'string',
		width: 50,
		columnClass: 'text-center',
	},
	{
		id: 'pro_target',
		title: '项目目标',
		type: 'string',
		width: 100,
		columnClass: 'text-center',
	}, {
		id: 'temp_desc',
		title: '标准任务',
		type: 'string',
		width: 100,
		columnClass: 'text-center',
	},
	{
		id: 'krs_desc',
		title: '子任务',
		type: 'string',
		columnClass: 'text-left',
	}, {
		id: 'finshtime',
		title: '完成时间',
		type: 'string',
		width: 100,
		columnClass: 'text-center',
	}, {
		id: 'kr_weight',
		title: 'KR权重',
		type: 'string',
		width: 50,
		columnClass: 'text-center',
		resolution: function (value, record, column, grid, dataNo, columnNo) {
			var content = value + '%';
			return content;
	}
	}, {
            id: 'input_weight',
            title: '投入占比',
            type: 'string',
            width: 50,
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                var content = value + '%';
                return content;
            }
        }, {
		id: 'task_fzuser',
		title: '成果负责人',
		type: 'string',
		width: 100,
		columnClass: 'text-center',
	}, {
		id: 'pro_role',
		title: '角色',
		// width: 100,
		type: 'string',
		columnClass: 'text-center',
		hideType: 'lg|md|sm|xs',
	}, {
		id: 'operation',
		title: '操作',
		width: 130,
		type: 'string',
		columnClass: 'text-center',
		resolution: function (value, record, column, grid, dataNo, columnNo) {
			var content = '';
			// 计算相差多少天
			// var d = new Date();
			// start=record.createTime.replace(/-/g,"/");
			// var startdate=new Date(start);
			// var time=d.getTime()-startdate.getTime();
			// var days=parseInt(time/(1000 * 60 * 60 * 24));
			//大于三天则不能修改和删除
			// if (days<=3){
			if (record.pro_state == 1) {
				content += '<button class="btn btn-xs btn-success" onclick="edit(\'' + record.krs_id + '\');"><i class="fa fa-edit"></i>  编辑</button>';
				content += '  ';
				content += '<button class="btn btn-xs btn-danger" onclick="remove(\'' + record.krs_id + '\');"><i class="fa fa-trash-o"></i>  删除</button>';

				content += '  ';
				if (record.rw_state == 0) {
					content += '<button class="btn btn-xs btn-warning" style="margin-top: 8px;" onclick="changeStat(\'' + record.krs_id + '\',2)"><i class="icon-retweet"></i>  终止</button>';
				}
				if (record.rw_state == 2) {
					content += '<button class="btn btn-xs btn-primary"  style="margin-top: 8px;" onclick="changeStat(\'' + record.krs_id + '\',0)"><i class="icon-retweet"></i>  运行</button>';
				}
				content += '  ';
				content += '<button class="btn btn-xs btn-primary"  style="margin-top: 8px;" onclick="sendMessage2(\'' + record.krs_id + '\');"><i class="icon-envelope-alt"></i>  通知</button>';
			}
			// content += '  ';
			// content += '<button class="btn btn-xs btn-primary" onclick=""><i class="icon-retweet"></i>  运行</button>';
			// }
			return content;
		}
	}
	];

	this.changeUser = function () {
		var user = $("#userId2").val();
		var iswc = $("#iswc").val();
		var rwState = $("#rwState").val();
		$("#okrContainer").empty();
		$("#okrToolBarContainer").empty();
		$CertusJsonAjax.dataInit("findProOkrPlanList", {
			"proId": proId,
			"targetId": targetId,
			"userId": user,
			"iswc": iswc,
			"rwState": rwState
		}, okrColumns, 'okrContainer', 'okrToolBarContainer', 20, [20, 30, 40]);
	};
	changeUser();

	this.changeStat = function (krsId, flag) {
		layer.confirm('确认变更子任务状态？', {
			btn: ['确认', '取消'] //按钮
		}, function (response) {
			var data = response.data;
			$certusUtils.ajax('changRwState', { "krsId": krsId, "flag": flag }, function () {
				changeUser();
				layer.msg('成功', {
					icon: 1
				});
			});
		});
	}
}
//通知人员
function sendMessage() {
	calcle();
	$("#jzMessage").show();
	// 优化版通知消息发送 start
	$certusUtils.ajax("findSpUserList", {}, function (response) {
		var nhlTeams = [];
		var data = response.data;
		for (var i = 0; i < data.length; i++) {
			var arr = {};
			arr.name = data[i].userName + "[" + data[i].positonName + "]";
			arr.id = data[i].userId;
			nhlTeams.push(arr);
		}
		//自动补全
		var nhl = $.map(nhlTeams, function (obj) {
			return {
				value: obj.name,
				data: { category: obj.id }
			};
		});
		// Initialize autocomplete with local lookup:
		$('#autocomplete').devbridgeAutocomplete({
			lookup: nhl,
			minChars: 1,
			onSelect: function (suggestion) {
				$("#searchParam").val(suggestion.data.category);
			},
			showNoSuggestionNotice: true,
			noSuggestionNotice: 'Sorry, no matching results'
		});
	});

	var size2 = 0;
	var userArr = "";
	//判断是否已选中分享人员
	this.searchPns = function () {
		$certusUtils.ajax("findProPns", { "proId": proId, "krsId": "1" }, function (result) {
			// 根据okrs_id获取对应通知成员列表
			var userData = result.data;
			$('#jz_notice').empty();

			// 循环并入成员组 or 循环输入tbody
			var userTbody = '';
			userList = [];
			for (var i = 0; i < userData.length; i++) {

				// 并入成员组
				userList.push(userData[i].user_id);

				// 状态值
				var email, wechat = '';
				if (userData[i].notice_control.indexOf(2) == -1) {
					email = '关闭';
				} else {
					email = '开启';
				}
				if (userData[i].notice_control.indexOf(1) == -1) {
					wechat = '关闭';
				} else {
					wechat = '开启';
				}

				//  循环数据
				userTbody += `<tr>
				<td>`+ userData[i].user_id + `</td>
				<td>`+ userData[i].user_name + `</td>
				<td>`+ userData[i].positon_name + `</td>
				<td>`+ email + `</td>
				<td>`+ wechat + `</td>
				<td>
					<button class="btn btn-xs btn-danger" onclick="delJzPerson('`+ userData[i].user_id + `')"><i class="fa fa-trash-o"></i> 删除</button>
				</td>
			</tr>`;
			}
			// 获取成员组长度
			size2 = userList.length;
			userArr = userList;
			// 循环输出tbody
			$('#jz_notice').append(userTbody);
		});
	};
	searchPns();

	this.addJzMessage = function () {
		if ($("#searchParam").val() == "") {
			layer.msg("请选择成员！");
			return;
		}

		if (userArr.indexOf($("#searchParam").val()) > -1) {
			layer.msg("成员已存在！");
			return;
		}
		if (size2 > 9) {
			layer.msg("最多只能添加10位成员！");
			return;
		}
		var arr = {};
		arr.userId = $("#searchParam").val();
		arr.email = $("#email").val();
		arr.weichat = $("#weichat").val();
		arr.proId = proId;
		arr.krsId = "1";
		var userName = $("#autocomplete").val();
		if (userName == "") {
			layer.msg("成员名称不能为空!");
			return;
		}
		$certusUtils.ajax("addProPns", { "param": JSON.stringify(arr) }, function () {
			layer.msg("添加成功");
			searchPns();

			//清空
			$("#searchParam").val("");
			$("#autocomplete").val("");
			$("#email").val("2");
			$("#weichat").val("1");
			userArr = "";
		});
	};

	this.delJzPerson = function (userId) {
		layer.confirm('确认删除此数据？', {
			btn: ['确认', '取消'] //按钮
		}, function () {
			$certusUtils.ajax("delProPns", { "userId": userId, "proId": proId, "krsId": "1" }, function () {
				layer.msg("删除成功");
				searchPns();
			});
		});
	};
}
// 项目整体进展-人员通知自动补全
$certusUtils.ajax("findSpUserList", {}, function (response) {
	var nhlTeams = [];
	var data = response.data;
	for (var i = 0; i < data.length; i++) {
		var arr = {};
		arr.name = data[i].userName + "[" + data[i].positonName + "]";
		arr.id = data[i].userId;
		nhlTeams.push(arr);
	}
	//自动补全
	var nhl = $.map(nhlTeams, function (obj) {
		return {
			value: obj.name,
			data: { category: obj.id }
		};
	});
	// Initialize autocomplete with local lookup:
	$('#autocomplete').devbridgeAutocomplete({
		lookup: nhl,
		minChars: 1,
		// onSelect: function (suggestion) {},
		showNoSuggestionNotice: true,
		noSuggestionNotice: 'Sorry, no matching results'
	});
});

function pushMsg() {
	var k = 0;
	var ustr = "";
	$("#userSelist").find("input[name='userBox']").each(function (i, n) {
		if ($(n).is(":checked")) {
			k++;
			ustr += "," + $(n).val();
		}
	});
	var fxbox = $("#subType").val();

	if (k > 10) {
		layer.msg("最多只能勾选10位成员");
		return;
	}

	$certusUtils.ajax("addFxUsers", {
		"proId": proId,
		"krsId": $("#keyId").val(),
		"userIds": ustr,
		"fxbox": fxbox
	}, function () {
		layer.msg("分享成功");
		calcle();
	});
}




function pushMsg2() {
	var k = 0;
	var ustr = "";
	$("#userSelist2").find("input[name='userBox']").each(function (i, n) {
		if ($(n).is(":checked")) {
			k++;
			ustr += "," + $(n).val();
		}
	});
	var fxbox = $("#subType2").val();

	if (k > 10) {
		layer.msg("最多只能勾选10位成员");
		return;
	}

	$certusUtils.ajax("addFxUsers", {
		"proId": proId,
		"krsId": $("#keyId2").val(),
		"userIds": ustr,
		"fxbox": fxbox
	}, function () {
		layer.msg("分享成功");
		clean2();
	});
}




function calcle() {
	$("#jzMessage").hide();
	$("#searchParam").val("");
	$("#autocomplete").val("");
	$("#email").val("2");
	$("#weichat").val("1");
}

// 优化版通知消息发送 end



function sends(krsId) {
	var k = 0;
	var ustr = "";
	$(".perlist").find("input[name='userBox']").each(function (i, n) {
		if ($(n).is(":checked")) {
			k++;
			ustr += "," + $(n).val();
		}
	});
	var fxbox = "";
	$(".perlist").find("input[name='fxbox']").each(function (i, n) {
		if ($(n).is(":checked")) {
			if (i == 0) {
				fxbox += $(n).val();
			} else {
				fxbox += "," + $(n).val();
			}
		}
	});

	if (k > 10) {
		layer.msg("最多只能勾选10位成员");
		return;
	}
	if (fxbox == "") {
		layer.msg("请选择分享方式");
		return;
	}

	$certusUtils.ajax("addFxUsers", {
		"proId": proId,
		"krsId": krsId,
		"userIds": ustr,
		"fxbox": fxbox
	}, function () {
		layer.msg("分享成功");
		layer.close(cindex);
	});
}

$("#addLeaf").bind("click", {
	isParent: false
}, add1);
$("#remove").bind("click", remove);
$("#toEdit").bind("click", toedit);

function addTask() {
	clean();
	var myDate = new Date();
	var month = myDate.getMonth() + 1;
	if (month >= 1 && month <= 3) {
		$("#exeCys").val("Q1");
	} else if (month >= 4 && month <= 6) {
		$("#exeCys").val("Q2");
	} else if (month > 7 && month <= 9) {
		$("#exeCys").val("Q3");
	} else {
		$("#exeCys").val("Q4");
	}
	$(".isshow").show();
	$("#chilName").focus();

	if ($('#addLeaf').css('display') != "none") {
		$('#toEdit').hide();
	} else {
		$('#toEdit').hide();
		$('#addLeaf').show();
	}
	// 可用
	// $('#addLeaf').hide() ;
}
$(".qxadd").click(function () {
	clean();
	$(".isshow").hide();
	//不可用
	$('#toEdit').hide();
	$('#addLeaf').hide();
	getList(0);
})

function clean() {
	// 项目目标
	$("#proTarget").val(0);
	// 动作分类
	$("#penNode").val("");
	// 标准动作
	$("#penName").val("");
	// 子任务
	$("#chilName").val("");
	// KR权重
	$("#krqz").val("");
	// 负责人
	$("#userId").val(0);
	// 完成时间
	$("#overtime").val("");
	// 投入占比
	$("#okrt").val("");
}


function add1(e) {
	var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
		nodes = zTree.getSelectedNodes(),
		treeNode = nodes[0];
	if (nodes.length <= 0) {
		layer.msg("请选择一个任务");
		return;
	};
	var node = treeNode.getParentNode();
	var chilName = $("#chilName").val();
	if (chilName == "") {
		layer.msg("子任务不能为空");
		return;
	};
	var krqz = $("#krqz").val();
	if (krqz == "") {
		layer.msg("KR权重不能为空");
		return;
	};
	var userId = $("#userId").val();
	if (userId == "") {
		layer.msg("负责人不能为空");
		return;
	};
	var overtime = $("#overtime").val();
	if (overtime == "") {
		layer.msg("完成时间不能为空");
		return;
	};
	var okrt = $("#okrt").val();
	if (okrt == "") {
		layer.msg("投入占比不能为空");
		return;
	};
	var list = {};
	list.krsDesc = chilName;
	list.krsWeight = krqz;
	list.fzUser = userId;
	list.findshTime = overtime;
	list.inputWeight = okrt;
	list.oId = treeNode.pId; //标准OId
	list.tId = treeNode.id; //标准任务ID
	list.tdesc = treeNode.name;
	list.odesc = node.name;
	list.targetId = $("#proTarget").val();
	list.exeCys = $("#exeCys").val();

	$certusUtils.ajax("addOkrTask2", {
		"list": JSON.stringify(list),
		"proId": proId,
		"pid": 0
	}, function () {
		clean();
		layer.msg("新增成功", {
			time: 1000
		});
		getList($("#proTarget").val());
	});
}

function edit(krsId) {
	$('#toEdit').show();
	// 可用
	$('#addLeaf').hide();

	$(".isshow").show();
	$("#chilName").focus();
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
	treeObj.cancelSelectedNode();
	$certusUtils.ajax("findKrsInfo", {
		"krsId": krsId
	}, function (result) {
		var data = result.data;
		$("#proTarget").val(data.targetId);
		$("#userId").val(data.taskFzuserId);
		$("#penNode").val(data.oDesc);
		$("#penName").val(data.tempDesc);
		$("#chilName").val(data.krsDesc);
		$("#krqz").val(data.krWeight);
		$("#overtime").val(data.time);
		$("#okrt").val(data.inputWeight);
		$("#krsId").val(krsId);
		$("#exeCys").val(data.exeCys)
	});
	// 不可用
	// $('#addLeaf').attr('disabled', 'true');
	// 可用
	// $('#toEdit').removeAttr('disabled');
}

function toedit(e) {
	layer.confirm('今日之前的历史数据不会修改，系统只修改今日之后的数据,是否确认修改？', {
		btn: ['确定', '取消'] //按钮
	}, function () {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			nodes = zTree.getSelectedNodes(),
			treeNode = nodes[0];
		// if ($("#krsId").val() == "") {
		//     layer.msg("请在列表中选择一个子任务进行编辑！", {
		//         time: 1000
		//     });
		//     return;
		// }
		var penNode = $("#penNode").val();
		var val = $("#chilName").val();
		var krqz = $("#krqz").val();
		var fzr = $("#userId").val();
		var overtime = $("#overtime").val();
		var okrt = $("#okrt").val();
		if (val == null || val == "" || val == undefined) {
			layer.msg("子任务不能为空！", {
				time: 1000
			});
			return;
		}
		if (krqz == null || krqz == "" || krqz == undefined) {
			layer.msg("KR权重不能为空！", {
				time: 1000
			});
			return;
		}
		if (fzr == null || fzr == "" || fzr == undefined) {
			layer.msg("负责人不能为空！", {
				time: 1000
			});
			return;
		}
		if (overtime == null || overtime == "" || overtime == undefined) {
			layer.msg("完成时间不能为空！", {
				time: 1000
			});
			return;
		}

		var toDay = new Date();
		if (Date.parse(overtime) < Date.parse(toDay)) {
			layer.msg("完成时间不能小于当前时间！");
			return;
		}

		if (okrt == null || okrt == "" || okrt == undefined) {
			layer.msg("投入百分比不能为空！", {
				time: 1000
			});
			return;
		} else {
			var list = {};
			list.krsDesc = val;
			list.krsWeight = krqz;
			list.fzUser = fzr;
			list.findshTime = overtime;
			list.inputWeight = okrt;
			list.targetId = $("#proTarget").val();
			list.krsId = $("#krsId").val();
			list.exeCys = $("#exeCys").val();
			if (treeNode != undefined) {
				list.krTempId = treeNode.id;
				list.oId = treeNode.pId;
				list.tempDesc = treeNode.name;
				list.oDesc = penNode;
				list.isTemp = 0;
			} else {
				list.isTemp = 1;
			}

			$certusUtils.ajax("updateOkrTask", {
				"list": JSON.stringify(list),
				"proId": proId
			}, function () {
				layer.msg("更新成功", {
					time: 1000
				});
				getList($("#proTarget").val());
			});
		}
	});
}

function remove(krsId) {
	layer.confirm('确认删除子任务节点？', {
		btn: ['确认', '取消'] //按钮
	}, function () {
		$certusUtils.ajax("deleteTask2", {
			"krsId": krsId
		}, function (result) {
			var data = result.data;
			if (data == true) {
				layer.msg('删除成功');
				toLoadHtml(4, 4);
			} else {
				layer.msg('当前子任务存有进展和得分，不能删除', {
					time: 1000,
					icon: 1
				});
			}
		});
	});
}


function onClick(event, treeId, treeNode, clickFlag) {
	var sNodes = $.fn.zTree.getZTreeObj("treeDemo").getSelectedNodes();
	if (sNodes[0].level == 2) {
		var id = sNodes[0].id;
		// $certusUtils.ajax("getTaskXx",{"krsId":id,"projId":proId,"pid":sNodes[0].pId}, function(result){
		//     var data = result.data;
		//     $("#krqz").val(data.kr_weight);
		//     $("#fzr").val(data.task_fzuser_id);
		//     $("#autocomplete").val(data.user_name+"["+data.positon_name+"]");
		//     $("#overtime").val(data.time);
		//     $("#okrt").val(data.input_weight);
		// });
	}
	var penNode, penName, chilName;
	if (sNodes.length > 0) {
		var node = sNodes[0].getParentNode();
		if (sNodes[0].pId == null || sNodes[0].pId == "" || sNodes[0].pId == undefined) {
			layer.msg("请选择展开后的子节点", {
				time: 500
			});
			return;
		}
		if (sNodes[0].pId < 10) {
			layer.msg("请选择展开后的子节点", {
				time: 500
			});
			return;
		}
		if (sNodes[0].pId != null || sNodes[0].pId != "" || sNodes[0].pId != undefined) {
			penNode = node.getParentNode();
			if (penNode != null) {
				penNode = penNode.name;
			}
			penName = node.name;
			chilName = sNodes[0].name;
			showLog(penNode, penName, chilName);
		}
	}

	var thid = $("#toEdit").css('display');
	if (thid == "none") {
		$('#addLeaf').show();
		$('#toEdit').hide();
	} else {
		$('#addLeaf').hide();
		$('#toEdit').show();
	}
}

function showLog(penNode, penName, chilName) {
	if (penNode != null) {
		$("#penNode").val(penName);
		$("#penName").val(chilName);
	} else {
		$("#penNode").val(penName);
		$("#penName").val(chilName);
	}
}

function dropPrev(treeId, nodes, targetNode) {
	var pNode = targetNode.getParentNode();
	if (pNode && pNode.dropInner === false) {
		return false;
	} else {
		for (var i = 0, l = curDragNodes.length; i < l; i++) {
			var curPNode = curDragNodes[i].getParentNode();
			if (curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
				return false;
			}
		}
	}
	return true;
}

function dropInner(treeId, nodes, targetNode) {
	if (targetNode && targetNode.dropInner === false) {
		return false;
	} else {
		for (var i = 0, l = curDragNodes.length; i < l; i++) {
			if (!targetNode && curDragNodes[i].dropRoot === false) {
				return false;
			} else if (curDragNodes[i].parentTId && curDragNodes[i].getParentNode() !== targetNode && curDragNodes[i].getParentNode().childOuter === false) {
				return false;
			}
		}
	}
	return true;
}

function dropNext(treeId, nodes, targetNode) {
	var pNode = targetNode.getParentNode();
	if (pNode && pNode.dropInner === false) {
		return false;
	} else {
		for (var i = 0, l = curDragNodes.length; i < l; i++) {
			var curPNode = curDragNodes[i].getParentNode();
			if (curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
				return false;
			}
		}
	}
	return true;
}
var log, className = "dark",
	curDragNodes, autoExpandNode;

function beforeDrag(treeId, treeNodes) {
	className = (className === "dark" ? "" : "dark");
	// showLog("[ " + getTime() + " beforeDrag ]&nbsp;&nbsp;&nbsp;&nbsp; drag: " + treeNodes.length + " nodes.");
	for (var i = 0, l = treeNodes.length; i < l; i++) {
		if (treeNodes[i].drag === false) {
			curDragNodes = null;
			return false;
		} else if (treeNodes[i].parentTId && treeNodes[i].getParentNode().childDrag === false) {
			curDragNodes = null;
			return false;
		}
	}
	curDragNodes = treeNodes;
	return true;
}

function beforeDragOpen(treeId, treeNode) {
	autoExpandNode = treeNode;
	return true;
}

function beforeDrop(treeId, treeNodes, targetNode, moveType, isCopy) {
	className = (className === "dark" ? "" : "dark");
	// showLog("[ " + getTime() + " beforeDrop ]&nbsp;&nbsp;&nbsp;&nbsp; moveType:" + moveType);
	// showLog("target: " + (targetNode ? targetNode.name : "root") + "  -- is " + (isCopy == null ? "cancel" : isCopy ? "copy" : "move"));
	return true;
}

function onDrag(event, treeId, treeNodes) {
	className = (className === "dark" ? "" : "dark");
	// showLog("[ " + getTime() + " onDrag ]&nbsp;&nbsp;&nbsp;&nbsp; drag: " + treeNodes.length + " nodes.");
}

function onDrop(event, treeId, treeNodes, targetNode, moveType, isCopy) {
	className = (className === "dark" ? "" : "dark");
	// showLog("[ " + getTime() + " onDrop ]&nbsp;&nbsp;&nbsp;&nbsp; moveType:" + moveType);
	// showLog("target: " + (targetNode ? targetNode.name : "root") + "  -- is " + (isCopy == null ? "cancel" : isCopy ? "copy" : "move"))
}

function onExpand(event, treeId, treeNode) {
	if (treeNode === autoExpandNode) {
		className = (className === "dark" ? "" : "dark");
		showLog("[ " + getTime() + " onExpand ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name);
	}
}
var log, className = "dark";

function beforeClick(treeId, treeNode, clickFlag) {
	className = (className === "dark" ? "" : "dark");
	showLog(treeNode.name);
	return (treeNode.click != false);
}

function change() {
	var isFinish = $("#isFinish").val();
	findOkrJZ(isFinish);
}
// OKR子任务进展
function findOkrJZ(isFinish) {
	$("#childrenContainer").empty();
	$("#childrenToolBarContainer").empty();
	var childrenColumns = [{
		id: 'pro_target',
		title: '项目目标',
		type: 'string',
		width: 100,
		columnClass: 'text-center',
	}, {
		id: 'krs_desc',
		title: '关键成果',
		type: 'string',
		// width: 230,
		columnClass: 'text-left',
	}, {
		id: 'task_fzuser',
		title: '负责人',
		type: 'string',
		hideType: 'lg|md|sm|xs',
		columnClass: 'text-center',
	}, {
		id: 'finshtime',
		title: '计划完成时间',
		type: 'string',
		width: 110,
		columnClass: 'text-center',
	}, {
		id: 'kr_wcl',
		title: '完成率',
		type: 'string',
		width: 60,
		columnClass: 'text-center',
		resolution: function (value, record, column, grid, dataNo, columnNo) {
			if (value==""){
				value=0;
			}
			var content = value + '%';
			return content;
	}
	}, {
		id: 'in_percent',
		title: '实际投入率',
		type: 'string',
		width: 100,
		columnClass: 'text-center',
		resolution: function (value, record, column, grid, dataNo, columnNo) {
            if (value==""){
                value=0;
            }
			var content = value + '%';
			return content;
	}
	}, {
		id: 'finish_cycle',
		title: '进展周期',
		type: 'string',
		width: 140,
		columnClass: 'text-center',
	}, {
		id: 'updateTime',
		title: '更新时间',
		type: 'string',
		width: 110,
		columnClass: 'text-center',
	}, {
		id: 'rw_desc',
		title: '子任务进展',
		type: 'string',
		columnClass: 'text-center',
		hideType: 'lg|md|sm|xs',
	}, {
		id: 'next_plan',
		title: '下一步计划',
		type: 'string',
		columnClass: 'text-center',
		hideType: 'lg|md|sm                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |xs',
	}, {
		id: 'operation',
		title: '操作',
		width: 80,
		type: 'string',
		columnClass: 'text-center',
		resolution: function (value, record) {
			var content = '';
			if (record.pro_state == 1) {
				if (record.kr_wcl != 100) {
					if (userId == record.task_fzuser_id) {
						content += '<button class="btn btn-xs btn-info" onclick="rechildren(\'' + record.krs_id + '\');"><i class="icon-refresh"></i>  更新</button>';
					}
				} else {
					content += '已完成';
				}
			}
			return content;
		}
	}];
	$CertusJsonAjax.dataInit("findProOkrList", {
		"proId": proId,
		"isFinish": isFinish
	}, childrenColumns, 'childrenContainer', 'childrenToolBarContainer', 20);
}

// 子任务数据更新
function rechildren(id) {
	toLoadHtml(13, id);
}
// 子任务自评得分
var childColumns = [{
	id: 'zhouqi',
	title: '周期',
	width: 50,
	type: 'string',
	columnClass: 'text-center',
}, {
	id: 'mubiao',
	title: '阶段目标',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'renwu',
	title: '标准任务',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'chengguo',
	title: '关键成果',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'planTime',
	title: '计划完成时间',
	type: 'string',
	width: 100,
	columnClass: 'text-center',
}, {
	id: 'kr',
	title: 'KR权重',
	type: 'string',
	width: 80,
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		var content = value + '%';
		return content;
}
}, {
	id: 'user',
	title: '成员',
	type: 'string',
	width: 80,
	columnClass: 'text-center',
}, {
	id: 't100',
	title: '投入百分比',
	width: 100,
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		var content = value + '%';
		return content;
}
}, {
	id: 'f1',
	title: '积极性',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f2',
	title: '沟通能力',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f3',
	title: '团队协作性',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f4',
	title: '创新力',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f5',
	title: '承诺性',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f6',
	title: '抗压力',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f7',
	title: '执行力',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f8',
	title: '责任心',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f9',
	title: '劳动态度',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f10',
	title: '总得分',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'operation',
	title: '操作',
	width: 130,
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		var content = '';
		content += '<button class="btn btn-xs btn-info" onclick="layer.msg(\'编辑：' + record.mubiao + '信息\');"><i class="fa fa-edit"></i>  编辑</button>';
		content += '  ';
		content += '<button class="btn btn-xs btn-danger" onclick="layer.msg(\'删除：' + record.mubiao + '信息\');"><i class="fa fa-trash-o"></i>  删除</button>';
		return content;
	}
}];

//任务得分
var taskScore = [{
	id: 'krs_desc',
	title: '关键成果',
	width: 250,
	type: 'string',
	columnClass: 'text-center',
}, {
	id: 'planTime',
	title: '计划完成时间',
	type: 'string',
	width: 100,
	columnClass: 'text-center',
}, {
	id: 'cycle',
	title: '完成周期',
	type: 'string',
	width: 180,
	columnClass: 'text-center',
}, {
	id: 'user',
	title: '负责人',
	type: 'string',
	width: 90,
	columnClass: 'text-center',
}, {
	id: 'oScore',
	title: 'o得分',
	type: 'string',
	columnClass: 'text-center',
}, {
	id: 'operation',
	title: '操作',
	width: 130,
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		var content = '';
		content += '<button class="btn btn-xs btn-info" onclick="layer.msg(\'编辑：' + record.mubiao + '信息\');"><i class="fa fa-edit"></i>  编辑</button>';
		content += '  ';
		content += '<button class="btn btn-xs btn-danger" onclick="layer.msg(\'删除：' + record.mubiao + '信息\');"><i class="fa fa-trash-o"></i>  删除</button>';
		return content;
	}
}];

var childOption = {
	lang: 'zh-cn',
	ajaxLoad: false,
	extraWidth: 20,
	// loadURL:'url',
	exportFileName: '子任务自评得分',
	datas: [{
		krs_desc: 'test',
		planTime: '2018-07-15',
		cycle: '7月5至07月15',
		user: '周昌东',
		oScore: '100',
	}],
	columns: taskScore,
	gridContainer: 'okrTaskScore',
	toolbarContainer: 'okrTaskScoreContainer',
	tools: '',
	pageSize: 10,
	pageSizeLimit: [10, 15, 20]
};
var childGrid = $.fn.dlshouwen.grid.init(childOption);
$(function () {
	childGrid.load();
});


var childOption = {
	lang: 'zh-cn',
	ajaxLoad: false,
	extraWidth: 20,
	// loadURL:'url',
	exportFileName: '子任务自评得分',
	datas: [{
		zhouqi: 'Q1',
		mubiao: '阶段目标测试数',
		renwu: '标准任务测试数',
		chengguo: '关键成果测试数',
		planTime: '2018-06-10',
		kr: '25%',
		user: '张三测试',
		t100: '100%',
		f1: '10分',
		f2: '10分',
		f3: '10分',
		f4: '10分',
		f5: '10分',
		f6: '10分',
		f7: '10分',
		f8: '10分',
		f9: '10分',
		f10: '100分',
	},],
	columns: childColumns,
	gridContainer: 'childContainer',
	toolbarContainer: 'childToolBarContainer',
	tools: '',
	pageSize: 10,
	pageSizeLimit: [10, 15, 20]
};
var childGrid = $.fn.dlshouwen.grid.init(childOption);
$(function () {
	childGrid.load();
});

// OKR子任务评分
var childsColumns = [{
	id: 'zhouqi',
	title: '周期',
	width: 50,
	type: 'string',
	columnClass: 'text-center',
}, {
	id: 'mubiao',
	title: '阶段目标',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'renwu',
	title: '标准任务',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'chengguo',
	title: '关键成果',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'planTime',
	title: '计划完成时间',
	type: 'string',
	width: 100,
	columnClass: 'text-center',
}, {
	id: 'kr',
	title: 'KR权重',
	type: 'string',
	width: 80,
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		var content = value + '%';
		return content;
}
}, {
	id: 'user',
	title: '成员',
	type: 'string',
	width: 80,
	columnClass: 'text-center',
}, {
	id: 't100',
	title: '投入百分比',
	width: 100,
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		var content = value + '%';
		return content;
}
}, {
	id: 'f1',
	title: '积极性',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f2',
	title: '沟通能力',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f3',
	title: '团队协作性',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f4',
	title: '创新力',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f5',
	title: '承诺性',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f6',
	title: '抗压力',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f7',
	title: '执行力',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f8',
	title: '责任心',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f9',
	title: '劳动态度',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f10',
	title: '总得分',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'operation',
	title: '操作',
	width: 130,
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		var content = '';
		content += '<button class="btn btn-xs btn-info" onclick="layer.msg(\'编辑：' + record.mubiao + '信息\');"><i class="fa fa-edit"></i>  编辑</button>';
		content += '  ';
		content += '<button class="btn btn-xs btn-danger" onclick="layer.msg(\'删除：' + record.mubiao + '信息\');"><i class="fa fa-trash-o"></i>  删除</button>';
		return content;
	}
}];
var childsOption = {
	lang: 'zh-cn',
	ajaxLoad: false,
	extraWidth: 20,
	// loadURL:'url',
	exportFileName: 'OKR子任务评分',
	datas: [{
		zhouqi: 'Q1',
		mubiao: '阶段目标测试数',
		renwu: '标准任务测试数',
		chengguo: '关键成果测试数',
		planTime: '2018-06-10',
		kr: '25%',
		user: '张三测试',
		t100: '100%',
		f1: '10分',
		f2: '10分',
		f3: '10分',
		f4: '10分',
		f5: '10分',
		f6: '10分',
		f7: '10分',
		f8: '10分',
		f9: '10分',
		f10: '100分',
	},],
	columns: childsColumns,
	gridContainer: 'childsContainer',
	toolbarContainer: 'childsToolBarContainer',
	tools: '',
	pageSize: 10,
	pageSizeLimit: [10, 15, 20]
};
var childsGrid = $.fn.dlshouwen.grid.init(childsOption);
$(function () {
	childsGrid.load();
});


// OKR负责人自评
var childbColumns = [{
	id: 'zhouqi',
	title: '周期',
	width: 50,
	type: 'string',
	columnClass: 'text-center',
}, {
	id: 'mubiao',
	title: '阶段目标',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'renwu',
	title: '标准任务',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'chengguo',
	title: '关键成果',
	type: 'string',
	columnClass: 'text-left',
}, {
	id: 'planTime',
	title: '计划完成时间',
	type: 'string',
	width: 100,
	columnClass: 'text-center',
}, {
	id: 'kr',
	title: 'KR权重',
	type: 'string',
	width: 80,
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		var content = value + '%';
		return content;
}
}, {
	id: 'user',
	title: '成员',
	type: 'string',
	width: 80,
	columnClass: 'text-center',
}, {
	id: 't100',
	title: '投入百分比',
	width: 100,
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		var content = value + '%';
		return content;
}
}, {
	id: 'f0',
	title: '领导力',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f1',
	title: '积极性',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f2',
	title: '沟通能力',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f3',
	title: '团队协作性',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f4',
	title: '创新力',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f5',
	title: '承诺性',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f6',
	title: '抗压力',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f7',
	title: '执行力',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f8',
	title: '责任心',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f9',
	title: '劳动态度',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'f10',
	title: '总得分',
	type: 'string',
	columnClass: 'text-center',
	hideType: 'lg|md|sm|xs',
}, {
	id: 'operation',
	title: '操作',
	width: 130,
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record, column, grid, dataNo, columnNo) {
		var content = '';
		content += '<button class="btn btn-xs btn-info" onclick="layer.msg(\'编辑：' + record.mubiao + '信息\');"><i class="fa fa-edit"></i>  编辑</button>';
		content += '  ';
		content += '<button class="btn btn-xs btn-danger" onclick="layer.msg(\'删除：' + record.mubiao + '信息\');"><i class="fa fa-trash-o"></i>  删除</button>';
		return content;
	}
}];
var childbOption = {
	lang: 'zh-cn',
	ajaxLoad: false,
	extraWidth: 20,
	// loadURL:'url',
	exportFileName: 'OKR负责人自评',
	datas: [{
		zhouqi: 'Q1',
		mubiao: '阶段目标测试数',
		renwu: '标准任务测试数',
		chengguo: '关键成果测试数',
		planTime: '2018-06-10',
		kr: '25%',
		user: '张三测试',
		t100: '100%',
		f0: '10分',
		f1: '10分',
		f2: '10分',
		f3: '10分',
		f4: '10分',
		f5: '10分',
		f6: '10分',
		f7: '10分',
		f8: '10分',
		f9: '10分',
		f10: '110分',
	},],
	columns: childbColumns,
	gridContainer: 'childbContainer',
	toolbarContainer: 'childbToolBarContainer',
	tools: '',
	pageSize: 10,
	pageSizeLimit: [10, 15, 20]
};
var childbGrid = $.fn.dlshouwen.grid.init(childbOption);
$(function () {
	childbGrid.load();
});


// OKR任务与分配—-人员通知自动补全
$certusUtils.ajax("findSpUserList", {}, function (response) {
	var nhlTeams = [];
	var data = response.data;
	for (var i = 0; i < data.length; i++) {
		var arr = {};
		arr.name = data[i].userName + "[" + data[i].positonName + "]";
		arr.id = data[i].userId;
		nhlTeams.push(arr);
	}
	//自动补全
	var nhl = $.map(nhlTeams, function (obj) {
		return {
			value: obj.name,
			data: { category: obj.id }
		};
	});
	// Initialize autocomplete with local lookup:
	$('#autocomplete2').devbridgeAutocomplete({
		lookup: nhl,
		minChars: 1,
		onSelect: function (suggestion) {
			$("#searchParam2").val(suggestion.data.category);
		},
		showNoSuggestionNotice: true,
		noSuggestionNotice: 'Sorry, no matching results'
	});
});

// OKR计划和分配-通知成员列表——清空方法
function cleanOkrs() {
	$("#jzMessage2").hide();
	$("#searchParam2").val("");
	$("#autocomplete2").val("");
	$("#email2").val("2");
	$("#weichat2").val("1");
};

// OKR计划和分配-通知成员列表——公共变量
var okrs_id = '';
var userList = [];
var size = 0;

//OKR计划和分配——通知成员列表——初始化加载方法
function sendMessage2(krsId) {
	// 清空控件值
	cleanOkrs();
	// 显示成员通知区块
	$("#jzMessage2").show();
	// 当前OKR任务赋值
	okrs_id = krsId;
	// 创建人员通知列表
	creatOkrs(okrs_id);
}

// 根据所选OKR创建对应人员通知列表--查询方法
function creatOkrs(okrs_id) {
	$('#okrs_notice').html('');
	// Ajax获取
	$certusUtils.ajax("findProPns", { "proId": proId, "krsId": okrs_id }, function (result) {
		// 加载

		// 根据okrs_id获取对应通知成员列表
		var userData = result.data;

		// 循环并入成员组 or 循环输入tbody
		var userTbody = '';
		userList = [];
		for (var i = 0; i < userData.length; i++) {

			// 并入成员组
			userList.push(userData[i].user_id);

			// 状态值
			var email, wechat = '';
			if (userData[i].notice_control.indexOf(2) == -1) {
				email = '关闭';
			} else {
				email = '开启';
			}
			if (userData[i].notice_control.indexOf(1) == -1) {
				wechat = '关闭';
			} else {
				wechat = '开启';
			}

			//  循环数据
			userTbody += `<tr>
				<td>`+ userData[i].user_id + `</td>
				<td>`+ userData[i].user_name + `</td>
				<td>`+ userData[i].positon_name + `</td>
				<td>`+ email + `</td>
				<td>`+ wechat + `</td>
				<td>
					<button class="btn btn-xs btn-danger" onclick="delOkrs('`+ userData[i].user_id + `')"><i class="fa fa-trash-o"></i> 删除</button>
				</td>
			</tr>`;
		}

		// 成员组
		// 获取成员组长度
		size = userList.length;
		// 循环输出tbody
		$('#okrs_notice').append(userTbody);
	});
}

// OKR计划和分配-成员通知列表-删除方法
function delOkrs(userId) {
	layer.confirm('确认删除此数据？', {
		btn: ['确认', '取消'] //按钮
	}, function () {
		$certusUtils.ajax("delProPns", { "userId": userId, "proId": proId, "krsId": okrs_id }, function () {
			layer.msg("删除成功");
			$('#okrs_notice').html('');
			creatOkrs(okrs_id);
		});
	});
};

// OKR计划和分配-成员通知列表-添加方法
function addOkrs() {
	if ($("#searchParam2").val() == "") {
		layer.msg("请选择成员！");
		return;
	}
	if (userList.indexOf($("#searchParam2").val()) > -1) {
		layer.msg("成员已存在！");
		return;
	}
	if (size > 9) {
		layer.msg("最多只能添加10位成员！");
		return;
	}
	var arr = {};
	arr.userId = $("#searchParam2").val();
	arr.email = $("#email2").val();
	arr.weichat = $("#weichat2").val();
	arr.proId = proId;
	arr.krsId = okrs_id;
	var userName = $("#autocomplete2").val();
	if (userName == "") {
		layer.msg("成员名称不能为空!");
		return;
	}

	$certusUtils.ajax("addProPns", { "param": JSON.stringify(arr) }, function () {
		layer.msg("添加成功");
		$('#okrs_notice').html('');
		// 清空控件值
		cleanOkrs();
		// 显示成员通知区块
		$("#jzMessage2").show();
		// 创建人员通知列表
		sendMessage2(okrs_id);
	});
}